package com.caishi.lkx;

import org.lionsoul.ip2region.xdb.Searcher;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class Ip2RegionDemo {
    public static void main(String[] args) throws IOException {
        // 加载 xdb 文件
        byte[] cBuff = Files.readAllBytes(Paths.get("F:\\server1\\question-bank-services-no-git\\question-server\\src\\main\\resources\\ip2region_v4.xdb"));
        Searcher searcher = Searcher.newWithBuffer(cBuff);

        // 查询 IP
        String ip = "1.2.4.8";
        try {
            String region = searcher.search(ip);
            System.out.printf("%s → %s\n", ip, region);
            // 输出示例：1.2.4.8 → 中国|广东省|广州市
        } catch (Exception e) {
            System.out.printf("查询失败: %s\n", e.getMessage());
        }
    }
}
